
#import "APDatePickerView.h"

@implementation APDatePickerView

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = UIColor.clearColor;
        _contentView = [[UIView alloc] init];
        _contentView.backgroundColor = [UIColor whiteColor];
        [self addSubview:_contentView];
        [_contentView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.mas_bottom).with.offset(0);
            make.left.and.right.equalTo(self).with.offset(0);
            make.top.equalTo(self);
        }];
        
        UIView *topLine = [[UIView alloc] init];
        topLine.backgroundColor = ColorWithHex(eeeeee);
        [_contentView addSubview:topLine];
        [topLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.and.right.equalTo(self.contentView).with.offset(0);
            make.height.mas_equalTo(1);
        }];
        
        UIView *sepLine = [[UIView alloc] init];
        sepLine.backgroundColor = ColorWithHex(eeeeee);
        [_contentView addSubview:sepLine];
        [sepLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(topLine.mas_bottom).with.offset(52);
            make.left.and.right.equalTo(self.contentView).with.offset(0);
            make.height.mas_equalTo(1);
        }];
        _datePicker = [[UIDatePicker alloc] init];
        _datePicker.maximumDate = [NSDate dateWithYear:[NSDate date].year - 18 month:1 day:1];
        _datePicker.datePickerMode = UIDatePickerModeDate;
        if (@available(iOS 13.4, *)) {
            _datePicker.preferredDatePickerStyle = UIDatePickerStyleWheels;
        }
//        [_datePicker setDate:[NSDate date] animated:YES];
//        [_datePicker setMaximumDate:[NSDate date]];
        [_contentView addSubview:_datePicker];
        [_datePicker mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(sepLine.mas_bottom).with.offset(0);
            make.left.bottom.and.right.equalTo(self).with.offset(0);
            make.height.mas_equalTo(263);
        }];
        
        
        _cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_cancelButton setTitle:@"取消" forState:UIControlStateNormal];
        [_cancelButton setTitleColor:ColorWithHex(999999) forState:UIControlStateNormal];
        _cancelButton.titleLabel.font = [UIFont systemFontOfSize:15];
        [_contentView addSubview:_cancelButton];
        _cancelButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _cancelButton.titleEdgeInsets = UIEdgeInsetsMake(0, 16, 0, 0);
        [_cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(topLine.mas_bottom).with.offset(0);
            make.bottom.equalTo(sepLine.mas_top).with.offset(0);
            make.left.equalTo(self.contentView.mas_left).with.offset(0);
            make.width.mas_equalTo(80);
        }];
       
        _sureButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_sureButton setTitle:@"确认" forState:UIControlStateNormal];
        [_sureButton setTitleColor:ColorWithHex(537cff) forState:UIControlStateNormal];
        _sureButton.titleLabel.font = [UIFont systemFontOfSize:15];
        [_contentView addSubview:_sureButton];
        _sureButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        _sureButton.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 16);
        [_sureButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(topLine.mas_bottom).with.offset(0);
            make.bottom.equalTo(sepLine.mas_top).with.offset(0);
            make.right.equalTo(self.contentView.mas_right).with.offset(0);
            make.width.mas_equalTo(80);
        }];
        
    }
    return self;
}


@end
